home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Integers
/
Integers.cp
next >
Wrap
Text File
|
1997-06-28
|
2KB
|
122 lines
// Integers.cp
#ifndef Integers_h
#include "Integers.h"
#endif
bool CanAdd( uint8 a, uint8 b )
{
return maxuint8 - a >= b;
}
bool CanAdd( uint16 a, uint16 b )
{
return maxuint16 - a >= b;
}
bool CanAdd( uint32 a, uint32 b )
{
return maxuint32 - a >= b;
}
bool CanAdd( int8 a, int8 b )
{
return ( a >= 0 )
? ( maxint8 - a >= b )
: ( minint8 - a <= b );
}
bool CanAdd( int16 a, int16 b )
{
return ( a >= 0 )
? ( maxint16 - a >= b )
: ( minint16 - a <= b );
}
bool CanAdd( int32 a, int32 b )
{
return ( a >= 0 )
? ( maxint32 - a >= b )
: ( minint32 - a <= b );
}
bool CanSubtract( uint8 a, uint8 b )
{
return a >= b;
}
bool CanSubtract( uint16 a, uint16 b )
{
return a >= b;
}
bool CanSubtract( uint32 a, uint32 b )
{
return a >= b;
}
bool CanSubtract( int8 a, int8 b )
{
return ( a >= 0 )
? ( a - maxint8 <= b )
: ( a - minint8 >= b );
}
bool CanSubtract( int16 a, int16 b )
{
return ( a >= 0 )
? ( a - maxint16 <= b )
: ( a - minint16 >= b );
}
bool CanSubtract( int32 a, int32 b )
{
return ( a >= 0 )
? ( a - maxint32 <= b )
: ( a - minint32 >= b );
}
bool CanMultiply( uint8 a, uint8 b )
{
return maxuint8 / a >= b;
}
bool CanMultiply( uint16 a, uint16 b )
{
return maxuint16 / a >= b;
}
bool CanMultiply( uint32 a, uint32 b )
{
return maxuint32 / a >= b;
}
bool CanMultiply( int8 a, int8 b )
{
int16 p = int16(a) * int16(b);
return p >= minint8 && p <= maxint8;
}
bool CanMultiply( int16 a, int16 b )
{
int32 p = int32(a) * int32(b);
return p >= minint16 && p <= maxint16;
}
bool CanMultiply( int32 a, int32 b )
{
if ( a == 0 )
return true;
if ( a > 0 )
if ( b > 0 )
return maxint32 / a >= b;
else
return minint32 / a <= b;
else
if ( b > 0 )
return minint32 / a >= b;
else
return maxint32 / a <= b;
}